const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const config = require('./config');
const database = require('./database');
const imageRoutes = require('./imageRoutes');
const tagRoutes = require('./tagRoutes');
const fileRoutes = require('./fileRoutes');  // 导入新的 fileRoutes
const bookmarkRoutes = require('./bookmarkRoutes');
const folderRoutes = require('./folderRoutes');


const cors = require('cors'); // 引入 cors 中间件

const app = express();
app.use(bodyParser.json());

app.use(cors({
    origin: '*'
}));

// 静态文件服务
// app.use('/mps/res', express.static("../public"));

// 使用文件路由
app.use('/', fileRoutes);

// API 路由
app.use('/mps', imageRoutes);
app.use('/mps', tagRoutes);
app.use('/mps', bookmarkRoutes);
app.use('/mps', folderRoutes);


// 启动服务器
async function startServer() {
    await database.connect();
    app.listen(config.port, () => {
        console.log(`Server is running on port ${config.port}`);
    });
}

startServer().catch(console.error);